Class Player

java.lang.Object
es.csic.iiia.fabregues.dip.Observer
es.csic.iiia.fabregues.dip.Player

public abstract class Player
extends Observer
Player of the game.
Author:
Angela Fabregues, IIIA-CSIC, fabregues@iiia.csic.es
  • Field Details

    • preferredPower

      protected java.lang.String preferredPower
      The power that this player prefers to play. After connecting to the server the player will send a message to the server to indicate its preference. There is no guarantee that the player will indeed be assigned this power, because this depends on the implementation of the server and on the preferences of the other players.
    • me

      protected Power me
    • passcode

      protected int passcode
  • Constructor Details

    • Player

      public Player()
      Player constructor
    • Player

      public Player​(java.lang.String logPath)
  • Method Details

    • getMe

      public Power getMe()
    • restart

      public void restart​(IComm commImpl, java.lang.String powerName, java.lang.String password) throws CommException
      Player constructor for reconnection
      Parameters:
      ip - of the server
      port - of the server
      name - of the player
      powerName - performed by the player in the previous connection
      password - of the player in the previous connection
      Throws:
      CommException
      CommException
      java.io.IOException
      CommException
    • reconnectionConfirmation

      public void reconnectionConfirmation​(java.lang.String powerName, int passcode)
      confirms the reconnection
      Parameters:
      powerName -
      passcode -
    • mapConfirmation

      public void mapConfirmation() throws CommException
      confirms the map
      Overrides:
      mapConfirmation in class Observer
      Throws:
      CommException
    • startPlaying

      public void startPlaying​(java.lang.String power, int passcode, int pressLevel)
      starts playing
      Parameters:
      power -
      passcode -
      pressLevel -
    • beforeNewPhase

      public void beforeNewPhase() throws CommException
      plays and sends the orders to the server
      Specified by:
      beforeNewPhase in class Observer
      Throws:
      CommException
    • sendOrders

      public void sendOrders​(java.util.List<Order> orders) throws CommException
      sends all orders to the server
      Parameters:
      orders -
      Throws:
      CommException
    • proposeDraw

      public void proposeDraw()
      Call this method to propose a draw. If all players that are not yet eliminated propose a draw in the same phase, then the server ends the game.
    • handleSlo

      public void handleSlo​(java.lang.String winner)
      ends the game when someone has won.
      Overrides:
      handleSlo in class Observer
      Parameters:
      winner -
    • afterOldPhase

      public void afterOldPhase()
      does something afterOldPhase
      Specified by:
      afterOldPhase in class Observer
    • play

      public abstract java.util.List<Order> play()
      plays selecting the orders to write if returned orders == null, orders are not send. Then you should send them using sendOrders()
      Returns:
      list of orders
    • start

      public abstract void start()
      starts the player when the powers are assigned
    • setMe

      public void setMe​(java.lang.String power)
    • submissionError

      public void submissionError​(java.lang.String[] message)
    • missingOrder

      public void missingOrder​(java.lang.String[] message)
    • isDead

      public boolean isDead()
    • getPreferredPower

      public java.lang.String getPreferredPower()
      Returns the name of the power that this player would prefer to play. May return null if this player has no preferred power.
      Returns:
      the preferredPower